/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			ETUndoElem.h
  \date			september 2011
  \author		TNick

  \brief		Contains the definition for ETUndoElem class


  Copyright (c) 2011, Nicu Tofan
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
 * Neither the name of the copyright holder nor the
   names of its contributors may be used to endorse or promote products
   derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL NICU TOFAN BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __ETUNDOELEM_INC__
#define __ETUNDOELEM_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<main.h>

class		ETI_CplxTxt;
class		ETSheetView;
class		ETSheet;
class		ETUndoHead;



#include	<generic/cc_l2d.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/// class representing the common interface exposed by all sub-items of a ETI_CplxTxt
/**
*
*/
class ETUndoElem : public CC_L2D		{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	friend class ETUndoHead;

protected:

	/// one bit switches
	enum Flags		{
		NOFLAGS = 0,

		STATE_UNDO_READY,	/**< the action was performed and the valid
action uppon this class is performUndo(); if this flag is not set, then
performUndo() is not valid and performRedo() is */

		MIRRORED,			/**< some commands may be implemented by
one class for two complementary actions (like create / delete). These
commands may use this flag to know wich version to
perform on undo / redo */


		MAX_FLAGS
	};


public:

	/// describes all possible types of undo elements
	enum	Type	{
		UNDEFINED = 0,

		CREATE_ITEM,	/**< ETU_CreateIt instance; mirror not set */
		DELETE_ITEM,	/**< ETU_CreateIt instance; mirror set */


		MAX_TY
	};


	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

protected:

	/// one bit switches used by this class and inheritants
	Flags		flg;

	/// description of this action
	QString		descr;

	/// the type of this action
	Type		the_type;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:

	/// constructor
	/**
   */
	ETUndoElem			( Type el_ty );


	/// destructor
	/**
  */
	virtual				~ETUndoElem		( void );





	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
	/** @name Undo / Redo status    */
	//@{
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
protected:

	/// marks this sub-item as being ready to be un-done
	void				setUndoReady	( void )
	{ flg = (Flags)(flg | STATE_UNDO_READY); }


	/// marks this sub-item as being ready to be re-done
	void				setRedoReady	( void )
	{ flg = (Flags)(flg & (~STATE_UNDO_READY)); }


public:
	/// tell if this item is ready to be undone
	bool				isUndoReady			( void ) const
	{ return ((flg & STATE_UNDO_READY) != 0); }


	/// tell if this item is ready to be undone
	bool				isRedoReady			( void ) const
	{ return ((flg & STATE_UNDO_READY) == 0); }


	//@}
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */





	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
	/** @name Associated text    */
	//@{
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
public:

	/// get the text that describes this instance
	inline QString		description			( void )
	{ return descr; }


protected:

	/// set the description for this item
	inline void			setDescription		(QString new_descr)
	{ descr = new_descr; }


	//@}
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */





	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
	/** @name  Mirrored status
 *
 *	Some commands may be implemented by one class for two
 *	complementary actions (like create / delete). These
 *	commands may use this flag to know wich version to
 *	perform on undo / redo
 */
	//@{
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
public:

	/// mark the item to be in mirrored form
	void				setMirrored			( void )
	{ flg = (Flags)(flg | MIRRORED); }

	/// mark the item to be in un-mirrored form
	void				setUnMirrored		( void )
	{ flg = (Flags)(flg & (~MIRRORED)); }

	/// tell if this item is in mirrored state
	bool				isMirrored			( void ) const
	{ return ((flg & MIRRORED) != 0); }

	//@}
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */





	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
	/** @name Reimplementing some CC_L2D functionality. Add new    */
	//@{
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
public:


	/// return next item
	inline ETUndoElem*		next		( void ) const
	{ return (ETUndoElem*)CC_L2D::next(); }


	/// return previous item
	inline ETUndoElem*		prev		( void ) const
	{ return (ETUndoElem*)CC_L2D::prev(); }


	/// gets the index of a particular item inside the father
	inline int				index		( const ETUndoHead* pFth) const
	{ return CC_L2D::index((CC_HDL2D*)pFth); }


protected:

	/// extract this item from the chain
	inline void				extract		(ETUndoHead* pFth)
	{ CC_L2D::extract((CC_HDL2D*)pFth); }


	/// simply breaks the chain before (places NULL in previous member)
	inline void				breakBefore	(void)
	{ LipP = NULL; }

	/// simply breaks the chain after (places NULL in next member)
	inline void				breakAfter	(void)
	{ LipN = NULL; }

	//@}
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */





	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
	/** @name Required to be implemented by inheritants    */
	//@{
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
public:


	/// perform the undo action
	virtual void			performUndo	( void ) = 0;


	/// perform the redo action
	virtual void			performRedo	( void ) = 0;


	//@}
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */





	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
	/** @name Various    */
	//@{
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
public:


	/// tell the type of this item
	inline Type			type				(void)
	{ return the_type; }


	//@}
	/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */





	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class ETUndoElem	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __ETUNDOELEM_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
